package com.item.springsecurity.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * _______                             __________
 * \      \   _______  __ ___________  \______   \__ __  ____
 * /   |   \_/ __ \  \/ // __ \_  __ \  |    |  _/  |  \/ ___\
 * /    |    \  ___/\   /\  ___/|  | \/  |    |   \  |  / /_/  >
 * \____|__  /\___  >\_/  \___  >__|     |______  /____/\___  /
 * \/     \/          \/                \/     /_____/
 *
 * @Auther: wangdong
 * @Description: TODO 线程池配置
 * @Date: 2019/4/25 16:54
 * @Version 1.0
 */
@Configuration
@EnableAsync
public class ThreadPoolConfig {
    @Bean
    public Executor getExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);//线程池维护线程的最少数量
        executor.setMaxPoolSize(30);//线程池维护线程的最大数量
        executor.setQueueCapacity(8); //缓存队列
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); //对拒绝task的处理策略
        executor.setKeepAliveSeconds(60);//允许的空闲时间
        executor.initialize();
        return executor;
    }
}